import log4js from 'log4js'
import { mysqlAppender } from '@/common/mysql-appender'

log4js.configure({
    appenders: {
        console: {
            type: "console"
        },
        file: {
            type: "file",
            filename: "logs/app.log",
            pattern: "yyyyMMdd",
            daysToKeep: 7,
            keepFileExt: true,
            alwaysIncludePattern: true
        },
        mysql: {
            type: mysqlAppender,
            config: {
                level: "info"
            }
        }
    },
    categories: {
        default: {
            level: "info",
            appenders: ["file", "console", "mysql"]
        }
    }
})

export const getLogger = (category?: string) : log4js.Logger => {
    const logger = log4js.getLogger(category || 'default')
    logger.level = process.env.LOG_LEVEL || 'info';
    return logger
}

export const logger = getLogger()